<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class LeavesController extends Controller
{
	
    public function getIndex(Request $request)
    {
        if($request['name']){
            $res = DB::table('leave')
            ->join('person','person.id','=','leave.PersonID')
            ->where('person.PersonName','like','%'.$request['name'].'%')
            ->select('leave.LeaveID','person.PersonName','leave.Reason','leave.LeaveDate','leave.Date','leave.State')
            ->orderby('leave.State','asc')
            ->paginate(4);
        }else{

            $res = DB::table('leave')
            ->join('person','person.id','=','leave.PersonID')
            ->select('leave.LeaveID','person.PersonName','leave.Reason','leave.LeaveDate','leave.Date','leave.State')
            ->orderby('leave.State','asc')
            ->paginate(4);
        }
        // dd($res);
        $info = $request->all();
        $num1 = count(DB::table('adjust')->where('Status',0)->get());
        $num2 = count(DB::table('leaveoffice')->where('Status',0)->get());
        $num3 = count(DB::table('leave')->where('State',0)->get());
        return view('allow/leaves/leaves',['res'=>$res,'info'=>$info,'num1'=>$num1,'num2'=>$num2,'num3'=>$num3]);
    }

    //审批
    public function getEdit($id)
    {
        //审批
        DB::table('leave')->where('LeaveID',$id)->update(['State'=>1]);
        return redirect('allow/leaves');
    }
   
    
}
